<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增职能年费用')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>


</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-expenseReportDep-add">
        <input id="id" name="id" class="form-control" type="hidden"/>
        <h4 class="form-header h4">选择项目信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label">工程公司：</label>
            <div class="col-sm-8">
                <select id="compId" name="compId" class="form-control noselect2">
                    <option value="">请选择</option>
                    <option th:each="pro:${userComp}"
                            th:value="${pro.compId}"
                            th:text="${pro.compName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">项目名称：</label>
            <div class="col-sm-8">
                <select class="form-control noselect2" id="pid" name="pid">
                    <option value="">请选择</option>

                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">年份：</label>
            <div class="col-sm-8">
                <select class="form-control noselect2" id="year" name="year">
                    <option value="">请选择</option>
                    <option>2019</option>
                    <option>2020</option>
                    <option>2021</option>
                    <option>2022</option>
                    <option>2023</option>
                    <option>2024</option>
                    <option>2025</option>
                </select>
            </div>
        </div>


    </form>

</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var expenseReportPrefix = ctx + "expenseReport";
    var compId;
    var html;
    var value;
    var data;
    $(function () {
        $("#compId").change(function () {
            compId = $("#compId option:selected").val();
            $.ajax({
                url: expenseReportPrefix + '/findProByCompId',
                data: {
                    "compId": compId,
                    "valueType" : '2'
                },
                success: function (data) {
                    $("#pid").find("option").remove();
                    if ($("#compId option:selected").val() == "") {
                        $("#pid").append('<option value="">请选择</option>')
                    }
                    for (var i in data.data) {
                        html = data.data[i].depOrProName;
                        value = data.data[i].id;
                        $("#pid").append('<option value="' + value + '">' + html + '</option>')
                    }
                }
            })
        });
    })

    function submitHandler() {
        data = {
            "compId": $("#compId").val(),
            "pid": $("#pid").val(),
            "year": $("#year").val(),
        }
        if ($("#compId").val() == "" || $("#proName").val() == "" || $("#year").val() == "") {
            alert("请检查工程公司、项目名称、费用类型、年份是否填写！");
        } else {
            $.ajax({
                url: expenseReportPrefix + '/findYearDepCount',
                data: {
                    "compId": $("#compId").val(),
                    "year": $("#year").val(),
                    "pid": $("#pid").val(),
                },
                success: function (row) {
                    if (row.code == 0) {
                        $.operate.save(expenseReportPrefix + "/addDepValue", data, undefined, 'actualValue');
                    } else {
                        alert(row.message);
                    }
                }
            })
        }
    }

</script>


</body>

</html>